package ie.timalb.chess.rules;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import ie.timalb.chess.Board;
import ie.timalb.chess.Movement;

public class RuleSet {
	Collection <Rule> rules;
	
	public RuleSet() 
	{
		rules = new ArrayList<Rule> ();
		Rule pawnCanMoveOneSquareForward = new PawnCanMoveOneSquareForward (); 
		
		rules.add(pawnCanMoveOneSquareForward);
	}

	public boolean validateMovement(Movement movement, Board board) {
		Iterator <Rule> ruleIterator = this.getRules().iterator();
		Rule ruleToValidate;
		boolean ruleValidated;
		boolean ruleSetValidated = true;
		boolean continueValidatingRules = true;
		
		do
		{
			if (ruleIterator.hasNext())
			{
				ruleToValidate = ruleIterator.next();
				ruleValidated = ruleToValidate.validateMovement (movement, board);
				if (!ruleValidated)
				{
					ruleSetValidated = false;
					continueValidatingRules = false;
				}
			}			
		}while (continueValidatingRules);
		
		return (ruleSetValidated);
	}

	public Collection<Rule> getRules() {
		return rules;
	}

	public void setRules(Collection<Rule> rules) {
		this.rules = rules;
	}

}
